package com.doone.telmarket.infrastructure.util;

import java.io.IOException;
import java.util.List;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;

import org.springframework.stereotype.Service;
import org.springframework.web.servlet.tags.RequestContextAwareTag;

import com.doone.telmarket.domain.ibator.ServiceType;
import com.doone.telmarket.domain.service.ServiceTypeOperation;

/**
 * @package com.doone.telmarket.infrastructure.util
 * @author 甘雨波
 * @description 读取增值业务服务类别的标签
 * @date
 */
@Service("serviceTypeTag")
public class ServiceTypeTag extends RequestContextAwareTag {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	public int doStartTagInternal() throws JspException {
		PageContext pc = pageContext;
		JspWriter jw = pc.getOut();
		try {
			ServiceTypeOperation serviceTypeOperation = (ServiceTypeOperation) getRequestContext()
					.getWebApplicationContext().getBean("ServiceTypeAble");
			List<ServiceType> serviceType = serviceTypeOperation.selectAllServiceType();
			jw.println("<select name='serviceType' id='serviceType'>");
			for (int i = 0; i < serviceType.size(); i++) {
				jw.println("<option value='" + serviceType.get(i).getServiceTypeId() + "'>");
				jw.println(serviceType.get(i).getServiceTypeName());
				jw.println("</option>");
			}
			jw.println("</select>");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return EVAL_PAGE;
	}

}
